package org.myorg.v6;

import org.myorg.v4.FGene4;
import org.myorg.v4.Fc4;
import org.myorg.v4.Gene4;

/* Mountain function
 * f(x) = 2x-1 if x included [0, 1]
 *        (N-x)/(N-1) x included (1, N]
 */

public class FMountain extends Fc4 {
	double low = 0;
	double high = 20;
	
	public double org_value(Gene4 ps) {
		FGene4 gene = (FGene4)ps;
		//double x = (high - low)*gene.geneAt(0) + low;
		//double tmp = (Math.PI + 100)*x/100 - 100;

		double tem = Long.parseLong(gene.gene, 2);
		double scope = Math.pow(2, gene.length) - 1;
		double x = tem/scope;

		return fc(x);
		
	}

	public double fc(double scope) {
		double y = 0;
		//double x = (high - low)*scope + low;
		double N = 20;
		double x = scope*N;
		if (x > 1)
			y = -(1d/6d)*x+(7d/6d);
			//y = (high - x)/(high - 1);
		else
			y = 2*x - 1;
		return y;
	}
	
}

